package com.momo.hr.controller.system;

import com.momo.hr.bean.Hr;
import com.momo.hr.bean.RespBean;
import com.momo.hr.bean.Role;
import com.momo.hr.service.HrService;
import com.momo.hr.service.system.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 操作员控制器
 */
@RestController
@RequestMapping("/system/hr")
public class HrController {

    @Autowired
    HrService hrService;

    @Autowired
    RoleService roleService;

    @GetMapping("/")
        public List<Hr> getAllHrs(String keywords){
        return this.hrService.getAllHrs(keywords);
    }

    @PutMapping("/")
    public RespBean updateHr(@RequestBody Hr hr){
        if(hrService.updateHr(hr) == 1){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");

    }

    @GetMapping("/roles")
    public List<Role> getAllRoles(){
        return this.roleService.getAllRoles();
    }


    @PutMapping("/updateHrRoles")
    public RespBean updateHrRoles(Integer hrid ,Integer[] rid){
        if(this.hrService.updateHrRoles(hrid,rid)){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("跟新失败");
    }
}

